
local EventBus = require "3rd/events"

-- base model
-- event dispatch and listener 
BaseModel = {mModelName = ""};


-- new
function BaseModel:New(o)
	o = o or {};
    setmetatable(o, self);
    self.__index = self;
    return o;
end

-- model name
function BaseModel:GetModelName()
	return self.mModelName;
end

-- @eventName such as property change
-- @... other params
function BaseModel:DispatchEvent(eventName, ...)
	-- body
	EventBus.Brocast(eventName, ...);
end

-- @eventName sub as other model change
-- @handler when event fired, call handler
function BaseModel:AddEventListener(eventName, handler)
	-- body
	EventBus.AddListener(eventName, handler);
end

-- @eventName which has been listener
-- @handler will be removed from listener
function BaseModel:RemoveListener(eventName, handler)
	-- body
	EventBus.RemoveListener(event, handler);
end

-- --------------------------------------------------------------------------------------------
-- User implement this function for user-define data struct
--
-- init model by outside data
-- override
function BaseModel:InitData(data)
	-- todo
end

function BaseModel:Clear()
	-- body
	-- todo: clear data struct, and clear listeners
end
-- --------------------------------------------------------------------------------------------